package com.cxrj.zhsq.interfaceManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cxrj.zhsq.partyMember.service.PartyMemberActivityService;
import com.cxrj.zhsq.partyMember.service.PartyMemberJobsService;
import com.cxrj.zhsq.partyMember.service.PartyMemberMienService;
import com.cxrj.zhsq.partyMember.service.PartyMemberStudyService;
import com.cxrj.zhsq.utils.IpUtil;

@Controller
@RequestMapping(value = "/interface")
public class InterfaceMemberController {

	@Resource
	private PartyMemberStudyService partyMemberStudyService;

	@Resource
	private PartyMemberActivityService partyMemberActivityService;

	@Resource
	private PartyMemberMienService partyMemberMienService;

	@Resource
	private PartyMemberJobsService partyMemberJobsService;

	/**
	 * 分页查询党建学习
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberStudy", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberStudy(String dataIndex, String pageCount, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberStudyService.selectMemberStudy(dataIndex, pageCount);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询党建学习
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberStudyId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberStudyId(String id, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberStudyService.selectById(id, request);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 分页查询党员活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberActivity(String dataIndex, String pageCount, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberActivityService.selectActivity(dataIndex, pageCount);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 分页查询我的党员活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberActivityByMy", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberActivityByMy(String userId, String status, String dataIndex, String pageCount, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberActivityService.selectActivityByMy(userId, status, dataIndex, pageCount);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询党员活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberActivityId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberActivityId(String activityId, String userId, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberActivityService.selectActivityById(activityId, userId, request, response);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 党员活动报名
	 */
	@RequestMapping(value = "insertActivityApply", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> insertSecretary(String userId, String activityId, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			map = partyMemberActivityService.insertActivityApply(userId, activityId);
		} catch (Exception e) {
			map.put("result", "0");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 分页查询党员风采
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberMien", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberMien(String dataIndex, String pageCount, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberMienService.selectMemberMien(dataIndex, pageCount);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 根据id查询党员活动
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberMienId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberMien(String id, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberMienService.selectPartyMemberMienById(id, request);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 党员活动取消报名
	 */
	@RequestMapping(value = "delActivityApply", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> delActivityApply(String userId, String activityId, HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			map = partyMemberActivityService.updateActivityApply(userId, activityId);
		} catch (Exception e) {
			map.put("result", "0");
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 分页查询党员任岗
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectMemberJobs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectMemberJobs(String userId, String dataIndex, String pageCount, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberJobsService.selectJobs(userId, dataIndex, pageCount);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 分页查询党员任岗
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertJobApply", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> insertJobApply(String userId, String jobsId, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = partyMemberJobsService.insertJobsApply(userId, jobsId, request);
			resultMap.put("path", "http://" + IpUtil.getIpAddr(request) + ":" + request.getServerPort() + "/zhsq_xg/");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}
}
